package qu.sol2bpel.services;

import java.util.StringTokenizer;

import javax.wsdl.*;

import com.ibm.wsdl.factory.WSDLFactoryImpl;
import com.ibm.wsdl.xml.WSDLReaderImpl;
public class Service_WSDL{


	private Definition wsdl_def;
	private String wsdlURI;
	public String getWsdlURI() {
		return wsdlURI;
	}

	public void setWsdlURI(String wsdlURI) {
		this.wsdlURI = wsdlURI;
	}

	private String url;
	public Definition getWsdl_def() {
		return wsdl_def;
	}

	public void setWsdl_def(Definition wsdl_def) {
		this.wsdl_def = wsdl_def;
	}

	public String getWSDLFileName()
	{
		StringTokenizer tokenizer = new StringTokenizer(wsdlURI,"\\");
		String filename = "";
		while(tokenizer.hasMoreTokens())
			filename = tokenizer.nextToken();
		int dot_index = filename.indexOf(".");
		filename = filename.substring(0,dot_index);
		return filename;
	}
	
	/*
	 * wsdlURI a URI (can be a filename or URL) pointing to a
	 WSDL XML definition.*/
	
	public Service_WSDL(Service_WSDL wsdl) 
	{
		this.url = wsdl.url;
		this.wsdl_def = wsdl.getWsdl_def();
		this.wsdlURI = wsdl.getWsdlURI();
	}
	public Service_WSDL(String wsdl_url) {
		// TODO Auto-generated constructor stub
	
		wsdlURI = new String(wsdl_url);
		WSDLFactoryImpl factory = null;
		try {
			factory = (WSDLFactoryImpl) WSDLFactoryImpl.newInstance();
		}
		catch (WSDLException we) {
			System.out.println("wsdl exception " + we.getMessage());
		}
		
		WSDLReaderImpl reader = (WSDLReaderImpl)factory.newWSDLReader();
		 try {
			
			 wsdl_def = reader.readWSDL(wsdlURI);
			 
			//System.out.println(wsdl_def.toString());
			
		} catch (WSDLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
	
	public static void main(String[] args)
	{
		Service_WSDL service1 = new Service_WSDL("E:\\QU\\BackupNov26\\BPELGenerator\\BPEL\\MatServ25.wsdl");
		
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

}
